package com.yzs.base.bus

import com.jeremyliao.liveeventbus.LiveEventBus
import com.jeremyliao.liveeventbus.core.LiveEvent
import com.jeremyliao.liveeventbus.core.LiveEventBusCore
import com.jeremyliao.liveeventbus.core.Observable

/**
 * author : yzs
 * time   : 2021/07/02
 * desc   :
 */

object LiveBus {
    private val bus by lazy { LiveEventBusCore.get() }

    @Synchronized
    fun <T> with(key: String?, type: Class<T>): Observable<T> {
        return bus.with(key, type)
    }

    operator fun <T : LiveEvent> get(eventType: Class<T>): Observable<T> {
        return LiveEventBus.get(eventType.name, eventType)
    }

    operator fun <T> get(key: String): Observable<T> {
        return LiveEventBus.get(key, Any::class.java) as Observable<T>
    }
}